home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-21 | 4.3 KB | 163 lines | [TEXT/MPS ] |
- { Miscellaneous routines used with the TCP XCMDs.
-
- This file in included in the other TCP XCMD source code files -- i.e., it is not compiled and
- linked separately.
-
- Copyright © 1988 Apple Computer, Inc.
-
- Initial coding 12/88 by Harry Chesley.
- }
-
- const
-
- TCPBUFFERSIZE = 4096; { Amount of space to allocate for each TCP connection (use the minimum to avoid heap fragging. }
- INCOMINGBUFSIZE = 1024; { Incoming buffer size (used by XCMDs for buffering). }
- MAGICNUMBER = 'TCPM'; { Unique value used to trap illegal connection IDs. }
-
- { csCodes for the TCP driver: }
- TCPcsCreate = 30;
- TCPcsPassiveOpen = 31;
- TCPcsActiveOpen = 32;
- TCPcsActOpenWithData = 33;
- TCPcsSend = 34;
- TCPcsNoCopyRcv = 35;
- TCPcsRcvBfrReturn = 36;
- TCPcsRcv = 37;
- TCPcsClose = 38;
- TCPcsAbort = 39;
- TCPcsStatus = 40;
- TCPcsExtendedStat = 41;
- TCPcsRelease = 42;
- TCPcsGlobalInfo = 43;
-
- type
-
- { TCP control block. Note: I'm using a really kludgy, reference by offset approach because the TCP package
- doesn't include Pascal definitions, only C. Eventually I hope they'll do Pascal and this can be converted to
- that approach. In the meantime, I don't want to reinvent wheels, etc. }
-
- TCPControlBlk =
- record
- qLink: QElemPtr;
- qType: INTEGER;
- ioTrap: INTEGER;
- ioCmdAddr: Ptr;
- ioCompletion: ProcPtr; {completion routine, or NIL if none}
- ioResult: OSErr; {result code}
- ioNamePtr: StringPtr; {ptr to pathname}
- ioVRefNum: INTEGER; {volume refnum}
- ioCRefNum: INTEGER; {device refnum}
- csCode: INTEGER; {control code}
- ioStreamPointer: longInt; {stream pointer}
- ioParms: array [32..150] of SignedByte;
- end;
-
- { TCP connection description: }
- TCPConnectionType =
- record
- magic: packed array [1..4] of char; { A magic number to try and avoid problems with released connection IDs. }
- asyncControlBlock: TCPControlBlk; { An IO control block for async open calls. }
- incomingPtr: Ptr; { Pointer into inBuf of next byte to read. }
- incomingSize: longInt; { Number of bytes left in inBuf. }
- buffer: array [1..TCPBUFFERSIZE] of SignedByte; { Connection buffer. }
- inBuf: array [1..INCOMINGBUFSIZE] of SignedByte; {Input buffer. }
- end;
-
- TCPConnectionPtr = ^TCPConnectionType;
-
- var
-
- Connection: TCPConnectionPtr;
- SyncControlBlock: TCPControlBlk;
-
- procedure GetStrParm(n: integer; var str: str255);
- { Get the nth parameter into str. }
-
- begin
- ZeroToPas(paramPtr,paramPtr^.params[n]^,str);
- end;
-
- function GetLongParm(n: integer): longInt;
- { Return the nth parameter string, interpreted as a long integer. }
-
- var str: str255;
-
- begin
- ZeroToPas(paramPtr,paramPtr^.params[n]^,str);
- GetLongParm := StrToNum(paramPtr,str);
- end;
-
- procedure SetUpConnectionID;
- { Get the first parameter, interpret it as a pointer, and store it in the Connection variable. }
-
- var portIndex: SPortSel;
-
- begin
- Connection := TCPConnectionPtr(GetLongParm(1));
- if Connection^.magic <> MAGICNUMBER then Fail('§§§ invalid connection ID §§§');
- SyncControlBlock := Connection^.asyncControlBlock;
- end;
-
- procedure PutControlByteAtOffset(b: SignedByte; o: longInt);
- { Put the specified byte at the offset given within the control block.}
-
- begin
- SyncControlBlock.ioParms[o] := b;
- end;
-
- procedure PutControlWordAtOffset(w: integer; o: longInt);
- { Put the specified word at the offset given within the control block.}
-
- var wPtr: ^integer;
-
- begin
- wPtr := @SyncControlBlock.ioParms[o];
- wPtr^ := w;
- end;
-
- procedure PutControlLongAtOffset(l: longInt; o: longInt);
- { Put the specified long at the offset given within the control block.}
-
- var lPtr: ^longInt;
-
- begin
- lPtr := @SyncControlBlock.ioParms[o];
- lPtr^ := l;
- end;
-
- function ControlByteAtOffset(o: longInt): SignedByte;
- { Return the byte at the offset given within the control block.}
-
- begin
- ControlByteAtOffset := SyncControlBlock.ioParms[o];
- end;
-
- function ControlWordAtOffset(o: longInt): integer;
- { Return the word at the offset given within the control block.}
-
- var wPtr: ^integer;
-
- begin
- wPtr := @SyncControlBlock.ioParms[o];
- ControlWordAtOffset := wPtr^;
- end;
-
- function ControlLongAtOffset(o: longInt): longInt;
- { Return the long at the offset given within the control block.}
-
- var lPtr: ^longInt;
-
- begin
- lPtr := @SyncControlBlock.ioParms[o];
- ControlLongAtOffset := lPtr^;
- end;
-
- procedure ZeroIOParms;
- { Zero out the control block, except for the IORefNum. }
-
- var i: integer;
-
- begin
- for i := 32 to 150 do PutControlByteAtOffset(0,i);
- end;
-